package com.aiolos.springboot.stepbystep.controller;

import com.aiolos.springboot.stepbystep.error.BusinessException;
import com.aiolos.springboot.stepbystep.model.AyUser;
import com.aiolos.springboot.stepbystep.service.IAyUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/ayUser")
public class AyUserController {

    @Resource
    private IAyUserService iAyUserService;

    @RequestMapping("/findAllUser")
    public String findAllUser(Model model){
        //查询数据库所有用户
        List<AyUser> userList = iAyUserService.findAll();
        model.addAttribute("users",userList);
        return "ayUser";
    }

    @RequestMapping("/findMap")
    public String findMap(Model model){
        return "map";
    }

    @RequestMapping("/throwBusinessException")
    public String throwBusinessException(Model model){
        //查询数据库所有用户
        List<AyUser> userList = iAyUserService.findAll();
        model.addAttribute("users",userList);
        //抛出业务异常
        throw new BusinessException("业务异常");
    }


    @RequestMapping("/findUserByNameAndPasswordRetry")
    public String findUserByNameAndPasswordRetry(Model model){

        AyUser ayUser = iAyUserService.findByNameAndPasswordRetry("阿毅","123456");
        model.addAttribute("users",ayUser);
        return "ayUser";
    }
}
